home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / code.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  5KB  |  204 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import sys
  5. import traceback
  6. from codeop import CommandCompiler, compile_command
  7. __all__ = [
  8.     'InteractiveInterpreter',
  9.     'InteractiveConsole',
  10.     'interact',
  11.     'compile_command']
  12.  
  13. def softspace(file, newvalue):
  14.     oldvalue = 0
  15.     
  16.     try:
  17.         oldvalue = file.softspace
  18.     except AttributeError:
  19.         pass
  20.  
  21.     
  22.     try:
  23.         file.softspace = newvalue
  24.     except (AttributeError, TypeError):
  25.         pass
  26.  
  27.     return oldvalue
  28.  
  29.  
  30. class InteractiveInterpreter:
  31.     
  32.     def __init__(self, locals = None):
  33.         if locals is None:
  34.             locals = {
  35.                 '__name__': '__console__',
  36.                 '__doc__': None }
  37.         
  38.         self.locals = locals
  39.         self.compile = CommandCompiler()
  40.  
  41.     
  42.     def runsource(self, source, filename = '<input>', symbol = 'single'):
  43.         
  44.         try:
  45.             code = self.compile(source, filename, symbol)
  46.         except (OverflowError, SyntaxError, ValueError):
  47.             self.showsyntaxerror(filename)
  48.             return False
  49.  
  50.         if code is None:
  51.             return True
  52.         
  53.         self.runcode(code)
  54.         return False
  55.  
  56.     
  57.     def runcode(self, code):
  58.         
  59.         try:
  60.             exec code in self.locals
  61.         except SystemExit:
  62.             raise 
  63.         except:
  64.             self.showtraceback()
  65.  
  66.         if softspace(sys.stdout, 0):
  67.             print 
  68.         
  69.  
  70.     
  71.     def showsyntaxerror(self, filename = None):
  72.         (type, value, sys.last_traceback) = sys.exc_info()
  73.         sys.last_type = type
  74.         sys.last_value = value
  75.         if filename and type is SyntaxError:
  76.             
  77.             try:
  78.                 (dummy_filename, lineno, offset, line) = (msg,)
  79.             except:
  80.                 pass
  81.  
  82.             value = SyntaxError(msg, (filename, lineno, offset, line))
  83.             sys.last_value = value
  84.         
  85.         list = traceback.format_exception_only(type, value)
  86.         map(self.write, list)
  87.  
  88.     
  89.     def showtraceback(self):
  90.         
  91.         try:
  92.             (type, value, tb) = sys.exc_info()
  93.             sys.last_type = type
  94.             sys.last_value = value
  95.             sys.last_traceback = tb
  96.             tblist = traceback.extract_tb(tb)
  97.             del tblist[:1]
  98.             list = traceback.format_list(tblist)
  99.             if list:
  100.                 list.insert(0, 'Traceback (most recent call last):\n')
  101.             
  102.             list[len(list):] = traceback.format_exception_only(type, value)
  103.         finally:
  104.             tblist = None
  105.             tb = None
  106.  
  107.         map(self.write, list)
  108.  
  109.     
  110.     def write(self, data):
  111.         sys.stderr.write(data)
  112.  
  113.  
  114.  
  115. class InteractiveConsole(InteractiveInterpreter):
  116.     
  117.     def __init__(self, locals = None, filename = '<console>'):
  118.         InteractiveInterpreter.__init__(self, locals)
  119.         self.filename = filename
  120.         self.resetbuffer()
  121.  
  122.     
  123.     def resetbuffer(self):
  124.         self.buffer = []
  125.  
  126.     
  127.     def interact(self, banner = None):
  128.         
  129.         try:
  130.             sys.ps1
  131.         except AttributeError:
  132.             sys.ps1 = '>>> '
  133.  
  134.         
  135.         try:
  136.             sys.ps2
  137.         except AttributeError:
  138.             sys.ps2 = '... '
  139.  
  140.         cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
  141.         if banner is None:
  142.             self.write('Python %s on %s\n%s\n(%s)\n' % (sys.version, sys.platform, cprt, self.__class__.__name__))
  143.         else:
  144.             self.write('%s\n' % str(banner))
  145.         more = 0
  146.         while None:
  147.             
  148.             try:
  149.                 if more:
  150.                     prompt = sys.ps2
  151.                 else:
  152.                     prompt = sys.ps1
  153.                 
  154.                 try:
  155.                     line = self.raw_input(prompt)
  156.                 except EOFError:
  157.                     self.write('\n')
  158.                     break
  159.  
  160.                 more = self.push(line)
  161.             continue
  162.             except KeyboardInterrupt:
  163.                 self.write('\nKeyboardInterrupt\n')
  164.                 self.resetbuffer()
  165.                 more = 0
  166.                 continue
  167.             
  168.  
  169.             return None
  170.  
  171.     
  172.     def push(self, line):
  173.         self.buffer.append(line)
  174.         source = '\n'.join(self.buffer)
  175.         more = self.runsource(source, self.filename)
  176.         if not more:
  177.             self.resetbuffer()
  178.         
  179.         return more
  180.  
  181.     
  182.     def raw_input(self, prompt = ''):
  183.         return raw_input(prompt)
  184.  
  185.  
  186.  
  187. def interact(banner = None, readfunc = None, local = None):
  188.     console = InteractiveConsole(local)
  189.     if readfunc is not None:
  190.         console.raw_input = readfunc
  191.     else:
  192.         
  193.         try:
  194.             import readline as readline
  195.         except ImportError:
  196.             pass
  197.  
  198.     console.interact(banner)
  199.  
  200. if __name__ == '__main__':
  201.     import pdb
  202.     pdb.run('interact()\n')
  203.  
  204.